function gui_close_figure(figure)
if isequal(get(figure, 'waitstatus'), 'waiting')
    % The GUI is still in UIWAIT, use UIRESUME
    uiresume(figure);
else
    % The GUI is no longer waiting, just close it
    delete(figure);
end

